package fifteenth.Java反射机制的深入应用;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class 调用类中的带参方法 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Class<?> c = Class.forName("fifteenth.取得类的结构.Person");
        Method method = c.getMethod("sayHello", String.class, int.class);
        String s = (String) method.invoke(c.newInstance(), "巴黎瑞亚", 19);//区别就是传递对象的要添加方法的参数名称
        System.out.print(s);
    }
}
/*
D:\WorkSpaces\Java\jdk-21\bin\java.exe "-javaagent:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\lib\idea_rt.jar=52253:D:\Software\IntelliJ IDEA\IntelliJ IDEA 2023.3.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\WorkSpaces\JavaDevelopBase_start_329\out\production\JavaDevelopBase_start_329 fifteenth.Java反射机制的深入应用.调用类中的带参方法
巴黎瑞亚，你好！今年我19岁了
Process finished with exit code 0

 */